﻿using System;
using System.Data;
using Moq;
using JTLeigh.Commerce.Spencer.Core.Common;

namespace JTLeigh.Commerce.Spencer.Core.Testing.Mocks.Data
{

	/// <summary>
	/// Mock database connection.
	/// </summary>
	/// <remarks>
	/// <para>
	/// <see cref="MockDatabaseConnection"/> ensures that the connection is opened, a command is 
	/// created, the connection is closed, and the connection is disposed.
	/// </para>
	/// </remarks>
	[CLSCompliant(false)]
	public class MockDatabaseConnection : Mock<IDbConnection>
	{

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="MockDatabaseConnection"/> class with the
		/// specified command.
		/// </summary>
		/// <param name="command">The <see cref="IDbCommand"/> that should be returned when
		/// <see cref="IDbConnection.CreateCommand"/> is called.</param>
		public MockDatabaseConnection(IDbCommand command)
			: base(MockBehavior.Strict)
		{
			Safety.AssertArgumentNotNull("command", command);

			Expect(x => x.Open()).AtMostOnce();
			Expect(x => x.CreateCommand()).Returns(command).AtMostOnce();
			Expect(x => x.Close()).AtMostOnce();
			Expect(x => x.Dispose()).AtMostOnce();
		}

		#endregion // Constructors

	}

}
